#ifndef __OJ_VIEW_HPP__
#define __OJ_VIEW_HPP__

#include <iostream>
#include <string>
#include "data.hpp"
#include <ctemplate/template.h>

namespace cloud
{
    class View
    {
    public:
        View()=default;
        ~View()=default;

        void AllExpandHtml(const std::vector<BackupInfo>& arry,std::string* html)
        {
            /*1.形成路径*/
            std::string src_html="./all_list.html";

            /*2.形成数字典*/
            ctemplate::TemplateDictionary root("all_questions");
            for(auto& iter:arry)
            {
                ctemplate::TemplateDictionary* sub=root.AddSectionDictionary("question_list");
                sub->SetValue("filename",FileUtil(iter._real_path).FileName());
                sub->SetValue("time",TimetoStr(iter._mtime));
                sub->SetValue("size",FsizetoStr(iter._fsize));
            }

            /*3.获取被渲染的html*/
            ctemplate::Template* tpl=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);

            /*4.开始完成渲染功能*/
            tpl->Expand(html,&root);
        }
    };
}

#endif